from typing import List, Union, Dict


def check_user_response(user_response: str) -> None:
    """ Проверяем ответ пользователя """

    try:
        list_numbers = user_response.split(', ')
        [int(number) for number in list_numbers]
    except ValueError:
        message = 'Проверьте формат записи. Введенные значения должны являться числами.'
        raise ValueError(message)


def get_user_response() -> str:
    """ Получаем ответ пользователя """

    message = 'Укажите массив чисел\nФормат: -3, 2, 3, 4, 5, 6, 7, 7, 8\n'
    response = input(message)
    check_user_response(response)
    return response


def format_user_response(user_response: str) -> List[int]:
    """ Форматируем ответ пользователя в нужный вид """

    list_numbers = user_response.split(', ')
    list_numbers = list(map(int, list_numbers))
    return list_numbers


def assign_numbers_to_groups(
    list_numbers: List[int]
) -> List[List[Union[str, int]]]:
    """ Распределяем номера по группам """

    set_of_numbers = []
    alphabet = list('abcdefghijklmnopqrstuvwxyz')

    for index, number in enumerate(list_numbers):

        if not index:
            set_of_numbers.append([alphabet[-1], index, number])
            continue

        previous_number = list_numbers[index-1]

        if previous_number + 1 == number:
            set_of_numbers.append([alphabet[-1], index, number])
        else:
            alphabet.pop(-1)
            set_of_numbers.append([alphabet[-1], index, number])

    return set_of_numbers


def make_numbers_look_right(
    numbers_by_groups: List[List[Union[str, int]]]
) -> Dict[str, str]:
    """ Приводим числа в нужный вид """

    result = {}

    for element in numbers_by_groups:
        designation, index, number = element

        if result.get(designation):
            result[designation] += f'{index} '
        else:
            result[designation] = f'{index} '

    return result


def get_result(number_indexes: Dict[str, str]) -> str:
    """ Получаем результат """

    set_of_indexes = {}

    for key in number_indexes:
        indexes = list(map(int, number_indexes[key].split()))
        quantity = len(indexes)
        set_of_indexes[quantity] = indexes


    m = max(set_of_indexes.keys())
    start, end = set_of_indexes[m][0], set_of_indexes[m][-1]
    result = f'{start}, {end}'
    return result


# ВЫШЕ ОПРЕДЕЛЕНИЕ ФУНКЦИЙ

user_response = get_user_response()
list_numbers = format_user_response(user_response)
numbers_by_groups = assign_numbers_to_groups(list_numbers)
number_indexes = make_numbers_look_right(numbers_by_groups)
result = get_result(number_indexes)
print('Result: ', result)
